#include<cstdio>//uncle-lu
#include<cstring>
#include<algorithm>
template<class T>void read(T &x)
{
	x=0;int f=0;char ch=getchar();
	while(ch<'0'||ch>'9') { f|=(ch=='-'); ch=getchar(); }
	while(ch<='9'&&ch>='0') { x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); }
	x = f ? -x : x;
	return ;
}

struct people{
	int x,y,z;
	int Id;
	friend bool operator<(const people a,const people b){
		if(a.x+a.y+a.z > b.x+b.y+b.z)
			return true;
		else if(a.x+a.y+a.z < b.x+b.y+b.z)
			return false;
		else
		{
			if(a.x>b.x)
				return true;
			else if(a.x<b.x)
				return false;
			else
				return a.Id<b.Id;
		}
	}
};
people line[310];
int n;

int main()
{
	read(n);
	for(int i=1;i<=n;++i)
	{
		read(line[i].x);read(line[i].y);read(line[i].z);
		line[i].Id = i;
	}

	std::sort(line+1,line+1+n);

	for(int i=1;i<=5;++i)
		printf("%d %d\n",line[i].Id,line[i].x+line[i].y+line[i].z);

	return 0;
}
